#安装docker
function installDocker(){

  yum-config-manager --add-repo https://mirrors.aliyun.com/repo/Centos-7.repo
  yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  yum makecache fast
  yum -y install yum-utils
  yum install -y device-mapper-persistent-data lvm2 nfs-utils  conntrack-tools
  yum install -y docker-ce-18.09.8
  yum install -y  docker-ce-cli-18.09.8
  systemctl daemon-reload
  systemctl enable docker
  systemctl restart docker
  docker version
}

#校验是否安装过docker，未安装过则执行安装，反之继续
if ! command -v docker &> /dev/null
then
  #执行安装
  installDocker
fi

#校验是否已经启动docker，未启动则执行启动程序，反之继续
status=`systemctl status docker`
result=$(echo $status | grep "running")
if [[ "$result" != "" ]]
then
   echo "docker already running"
else
   systemctl start docker
fi